export function loadBMap (ak) {
  ak = ak || 'G1LFyjrNGIkns5OfpZnrCGAKxpycPLwb'
  return new Promise((resolve, reject) => {
    if (typeof window.BMap !== 'undefined') return resolve(window.BMap)

    window.onBMapCallback = _ => resolve(window.BMap)
    const script = document.createElement('script')
    script.type = 'text/javascript'
    script.src = 'https://api.map.baidu.com/api?v=2.0&ak=' + ak + '&callback=onBMapCallback'
    script.onerror = reject
    document.head.appendChild(script)
  })
}
